package com.itstyle.quartz.web;


import com.itstyle.quartz.entity.Result;
import com.itstyle.quartz.entity.Userinfo;
import com.itstyle.quartz.service.IUserinfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserinfoController {


    @Autowired
    private IUserinfoService userinfoService;


    @PostMapping("/list")
    public Result list(Userinfo userinfo, Integer pageNo, Integer pageSize) {
        return userinfoService.listUserinfo(pageNo, pageSize);
    }


    @PostMapping("/add")
    public Result save(Userinfo userinfo) {
        try {
            userinfoService.save(userinfo);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error();
        }
        return Result.ok();
    }

    @PostMapping("/remove")
    public Result remove(Userinfo userinfo) {
        try {
            userinfoService.delete(userinfo);
        } catch (Exception e) {
            e.printStackTrace();
            Result.error();
        }
        return Result.ok();
    }

    @PostMapping("/update")
    public Result update(Userinfo userinfo) {
        try {
            userinfoService.update(userinfo);
        } catch (Exception e) {
            e.printStackTrace();
            Result.error();
        }
        return Result.ok();
    }


}
